/**
 * 问诊单
 * Created by wxg on 2018/5/13.
 */

$(function(){
    var doctorId = getQueryString("doctorId");
    var data = {"doctorId":doctorId};
    // 获取问诊单列表
    $.ajax({
        url: "/inquiry/getListByDoctorId",
        type: "post",
        dataType: "json",
        data: data,
        success: function (result) {
            console.log("问诊单数量："+result.data.inquirys.length);
            // 存储结果字符串
            var inquiryList = "";
            // 存储一级分类列表
            var level1List = $(result.data.categoryList);
            // 存储二级&三级分类列表
            var level2List = $(result.data.categoryList2);
            $(result.data.inquirys).each(function(i){
                console.log(this.patient.patientname);
                console.log(this.id);
                inquiryList += "<div class='inquiry-block'>"+
                "<label class='weui-cell weui-check__label block-head' onclick='detailLink("+this.id+")' >"+
                    "<div class='weui-cell__hd'>"+
                    "<img src='../images/an.png' width='20px'>"+
                    "</div>"+
                    "<div class='weui-cell__bd'>"+
                    "<p>问诊单</p>"+
                    "</div>"+
                    "<div class='weui-cell__bd'>"+
                    "<span class='view-link'>点击查看</span>"+
                    "</div>"+
                    "</label>"+
                    "<div class='block-body'>"+
                    "<label class='weui-cell weui-check__label'>"+
                    "<div class='weui-cell__hd c-title' >"+
                    "患者："+
                "</div>"+
                "<div class='weui-cell__bd' style='width: 100%'>"+this.patient.patientname+"，"+this.patient.age+"岁</div></label><label class='weui-cell weui-check__label'>"+
                    "<div class='weui-cell__hd c-title' >患者主诉：</div><div class='weui-cell__bd' style='width: 100%'>"+
                    this.description+"</div></label>";

                level1List.each(function(j){
                    var flag = true;
                    if(this.categoryId<5){
                            // 获取分类明细与内容
                            level2List.each(function(k){
                               //console.log(level1List[j].categoryCode+level1List[j].content+level2List[k].parentCode);
                                //console.log("----"+level2List[k].parentCode+"---");

                                if(level1List[j].categoryCode==level2List[k].parentCode && flag){
                                   inquiryList+="<label class='weui-cell weui-check__label'><div class='weui-cell__hd c-title' >"+level1List[j].content+"：</div> <div class='weui-cell__bd' style='width: 100%'>";  // 追加一级分类
                                    flag = false;
                               }
                                // 显示三级分类内容
                                if(level1List[j].categoryCode==level2List[k].parentCode){
                                    inquiryList+=level2List[k].item.itemTitle+"，";
                                }

                           });
                                inquiryList+="</div></label>";
                        }
                    });
                    inquiryList+="</div></div>";
            });
            $("#inquiry-list").html(inquiryList);
        }, error: function () {
            alert("ajax出错");
        }
    });
});